<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<input id="tel" type="tel" placeholder="手机号">
<button id="getCode">获取验证码</button><br>
<input id="validCode" type="text" placeholder="验证码">
<button id="submit">提交</button>
</body>
<script>
    window.onload = function () {
        var telIpt = document.getElementById('tel');
        var getCodeBtn = document.getElementById('getCode');
        var validCode = document.getElementById('validCode');
        var submitBtn = document.getElementById('submit');
        getCodeBtn.onclick = function () {
            var val = telIpt.value;
            var telReg = /^1[35789]\d{9}$/;
            if(telReg.test(val)){
                $.ajax({
                    method:'get',
                    url:'http://localhost:8080/validCodeMsg',
                    data: {
                        phoneNumber: val
                    },
                    success: function (data) {
                        console.log(data);
                    },
                    fail: function (error) {
                        console.log(error);
                    }
                })
            }
        }
        submitBtn.onclick = function () {
            $.ajax({
                url:'http://localhost:8080/valid',
                method:'get',
                data:{
                    code: validCode.value
                },
                success: function (data) {
                    console.log(data);
                },
                fail: function (error) {
                    console.log(error)
                }
            })
        }
    }
</script>
</html>